package graphmanip.collapsing;


import graphmanip.CollapsingMethod;

import java.util.ArrayList;

import commonfunctions.Matrix;

public class NaiveCollapsing extends CollapsingMethod
{
	public ArrayList<ArrayList<Integer>> collapse(Matrix weights) 
	{
		ArrayList<ArrayList<Integer>> output = new ArrayList<ArrayList<Integer>>();
		
		for (int i = 0; i < weights.length(); i++)
		{
			int numPositive = -1;
			for (int j = 0; j < weights.length(); j++)
			{
				if (weights.get(i, j) > 0.0 && numPositive == -1)
					numPositive = j;
				else if (weights.get(i, j) > 0.0)
				{
					numPositive = -1;
					break;
				}
			}
			if (numPositive != -1)
			{
				int nextValue = -1;
				for (int j = 0; j < weights.length(); j++)
				{
					if (weights.get(j, numPositive) > 0.0)
					{
						nextValue = j;
					}
					if (nextValue != i && nextValue != -1)
						break;
				}
				if (nextValue == i)
				{
					ArrayList<Integer> toAdd = new ArrayList<Integer>();
					toAdd.add(nextValue);
					toAdd.add(numPositive);
					output.add(toAdd);
				}
			}
		}

		return output;
	}
	
}
